{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "So far you mastered the notation of quantum mechanics and quantum computing, understood as much physics as needed to perform various operations on quantum states, and now you are ready to build quantum algorithms. In this notebook, we look at the basics of gate-model quantum computing, which is sometimes also referred to as universal quantum computing. Most academic and commercial efforts to build a quantum computer focus on this model: Alibaba, Baidu, Google, HP, IBM Q, Intel, IonQ, Microsoft, Rigetti Computing, and Tencent all aim at this, and the list keeps expanding. It remains unclear which implementation will prove scalable: superconducting chips, photonic systems, and ion traps are the most common types, each having its own advantages and disadvantages. We abstract away, we focus on the quantum algorithms irrespective of the physical implementation.\n",
    "\n",
    "To get there, first we have to familiarize ourselves with some gates and what happens to those gates on quantum computers. The following diagram shows the software stack that bridges a problem we want to solve with the actual computational back-end [[1](#1)]:\n",
    "\n",
    "<img src=\"figures/universal_quantum_workflow.png\" alt=\"Software stack on a gate-model quantum computer\" style=\"width: 400px;\"/>\n",
    "\n",
    "First, we define the problem at a high-level and a suitable quantum algorithm is chosen. Then, we express the quantum algorithm as a quantum circuit composed of gates. This in turn has to be compiled to a specific quantum gate set available. The last step is to execute the final circuit either on a quantum processor or on a simulator.\n",
    "\n",
    "The quantum algorithms we are interested in are about machine learning. In this notebook, we look at the levels below algorithms: the definition of circuits, their compilation, and the mapping to the hardware or a simulator.\n",
    "\n",
    "\n",
    "# Defining circuits\n",
    "\n",
    "Circuits are composed of qubit registers, gates acting on them, and measurements on the registers. To store the outcome of registers, many quantum computing libraries add classical registers to the circuits. Even by this language, you can tell that this is a very low level of programming a computer. It resembles the assembly language of digital computers, in which a program consists of machine code instructions.\n",
    "\n",
    "Qubit registers are indexed from 0. We often just say qubit 0, qubit 1, and so on, to refer to the register containing a qubit. This is not to be confused with the actual state of the qubit, which can be $|0\\rangle$, $|1\\rangle$, or any superposition thereof. For instance, qubit 0 can be in the state $|1\\rangle$.\n",
    "\n",
    "Let's take a look at the gates. In digital computing, a processor transform bit strings to bit strings with logical gates. Any bit string can be achieved with just two gates, which makes universal computations possible with simple operations composed only of these two types of gates. It is remarkable and surprising that the same is also true for quantum computers: any unitary operation can be decomposed into elementary gates, and three types of gates are sufficient. This is remarkable since we are talking about transforming continuous-valued probability amplitudes, not just discrete elements. Yet, this result is what provides the high-level theoretical foundation for being able to build a universal quantum computer at all.\n",
    "\n",
    "Let's look at some common gates, some of which we have already seen. Naturally, all of these are unitary.\n",
    "\n",
    "| Gate |Name                | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Matrix |\n",
    "|------|--------------------|---------------------------------------------------------------------|\n",
    "|   X  | Pauli-X or NOT gate|$\\begin{bmatrix}0 & 1\\\\ 1& 0\\end{bmatrix}$|\n",
    "|   Z  | Pauli-Z  gate      |$\\begin{bmatrix}1 & 0\\\\ 0& -1\\end{bmatrix}$|\n",
    "|  H   | Hadamard gate      |$\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1 & 1\\\\ 1& -1\\end{bmatrix}$|\n",
    "| Rx($\\theta$)| Rotation around X|$\\begin{bmatrix}\\cos(\\theta/2) & -\\imath \\sin(\\theta/2)\\\\ -\\imath \\sin(\\theta / 2) & \\cos(\\theta / 2)\\end{bmatrix}$|\n",
    "| Ry($\\theta$)| Rotation around Y|$\\begin{bmatrix}\\cos(\\theta/2) & -\\sin(\\theta/2)\\\\ -\\sin(\\theta / 2) & \\cos(\\theta / 2)\\end{bmatrix}$|\n",
    "| CNOT, CX | Controlled-NOT | $\\begin{bmatrix}1 & 0 & 0 &0\\\\ 0 & 1 & 0 &0\\\\ 0 & 0 & 0 &1\\\\ 0 & 0 & 1 &0\\end{bmatrix}$|\n",
    "\n",
    "As we have seen before, the rotations correspond to axis defined in the Bloch sphere. \n",
    "\n",
    "There should be one thing immediately apparent from the table: there are many, in fact, infinitely many single-qubit operations. The rotations, for instance, are parametrized by a continuous value. This is in stark contrast with digital circuits, where the only non-trivial single-bit gate is the NOT gate.\n",
    "\n",
    "The CNOT gate is the only two-qubit gate in this list. It has a special role: we need two-qubit interactions to create entanglement. Let's repeat the circuit for creating the $|\\phi^+\\rangle = \\frac{1}{\\sqrt{2}}(|00\\rangle+|11\\rangle)$. We will have two qubit registers and two classical registers for measurement output. First, let's define the circuit and plot it:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-19T20:07:24.314851Z",
     "start_time": "2018-11-19T20:07:22.576203Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/pwittek/.anaconda3/envs/qiskit/lib/python3.7/site-packages/marshmallow/schema.py:364: ChangedInMarshmallow3Warning: strict=False is not recommended. In marshmallow 3.0, schemas will always be strict. See https://marshmallow.readthedocs.io/en/latest/upgrading.html#schemas-are-always-strict\n",
      "  ChangedInMarshmallow3Warning\n",
      "/home/pwittek/.anaconda3/envs/qiskit/lib/python3.7/site-packages/qiskit/tools/visualization/_circuit_visualization.py:206: DeprecationWarning: The current behavior for the default output will change in a future release. Instead of trying latex and falling back to mpl on failure it will just use \"text\" by default\n",
      "  '\"text\" by default', DeprecationWarning)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAACuCAIAAABiCIUHAAAmk0lEQVR4nO2dfVhUxR7HZ5eFRYUAhYTbqovJW+LLYqSVJhA3QkMgWfBqUigW3EofTQOri9fAkvQhU1DyeVrQ1AdQSbgGXFTUJ7peNQJFfOFleWdBcGEBYYF9uX9Mz7nbvnH27Dn7AvP5h2HOzJzvwPzOnJkzMz+aXC4HCDOnvr7ezc3N2Cr+hJOT0+PHj42twnAwjC0AQQJ0Oh0AsGvXLl9fX2NrAQCAI0eOCIVCY6swKMiQJg6vvPJKWFiYsVUAAEBBQcHQ0JCxVRgUurEFIBATgcloSBKJZHR0lKzSRkZGyCoKYb5MRkOKj49/9913ySqNzWYfPXqUrNIQZspkNKTOzs7Ozk6ySvPx8Tly5AhZpSHMFNI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Cy+8YNw/r3ba29tlMtmsWbOoKLylpYXBYOg6StywYQPJhtTa2goD2Kf9ccF8gENvyqpgjXL+/Pn6qSMNSjXT6XQmk0lYmz7QaDQGg2HKVgQAoHQDsoWFBYHymUwmyYaEidA0eFDF29vb2tpaLBZXVFSoTVBdXQ0AcHBwcHNzI0Wk/lCqmclknj59Wl+JCMNCsnF7eXnBQE1NDc4sTCYzJCQEAHD9+vXu7m6lq21tbbdu3QIAhIWFmc6T0hw1IyiFZEOaM2cOfL8sKCi4f/++aoK7d+9mZGQoRUZHRwMAxGJxamqq0qXk5GS5XA4AiImJIVeqnpijZgSFkL4xIzs7G5bs4uKSl5fX3d09NDRUV1d3+vTpsLAwOp3+0UcfqeaCa1hpNNrx48exyPT0dPiuGBoaqul2iYmJAIBDhw4RU8vlclksFovFamxs1DUvYc2IiQf5hiSTyd58801NdmtnZ3f+/HnVXG1tbS4uLjCNj49PREQENrpgs9kCgUDT7fQ0JD8/P3iX+vp6XfMS1oyYeFCyQ3ZkZGTPnj0ODg6KJuTp6XngwAGRSKQpl0AggBtLFQkKCurq6tJyLyMaEmHNiIkHTS6Xj//+R4ixsTH4WcnOzo7NZuNcFVpZWVlaWtrd3c1isQICArCJZk3s3r17//79hw4dIrbWjhR01YyYeFC4H8nS0tLHx0fXXBwOh8PhUKGHOsxRM4JcjL/VHIGYAJjc2d84KSoqgh89b9y4AQC4fPmyWCwGACxbtmzlypVGFoeYfFA4RqKUmJgYbJ5dkcTExK+//trgchCTnf8BaaLBvBYY48QAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGB size=280x174 at 0x7FBF347776D8>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister\n",
    "from qiskit import execute\n",
    "from qiskit import BasicAer\n",
    "from qiskit.tools.visualization import circuit_drawer, plot_histogram\n",
    "\n",
    "q = QuantumRegister(2)\n",
    "c = ClassicalRegister(2)\n",
    "circuit = QuantumCircuit(q, c)\n",
    "circuit.h(q[0])\n",
    "circuit.cx(q[0], q[1])\n",
    "circuit_drawer(circuit)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that we can't just initialize the qubit registers in a state we fancy. All registers are initialized in $|0\\rangle$ and creating a desired state is **part** of the circuit. In a sense, arbitrary state preparation is the same as universal quantum computation: the end of the calculation is a state that we desired to prepare. Some states are easier to prepare than others. The above circuit has only two gates to prepare our target state, so it is considered very easy.\n",
    "\n",
    "Let us see what happens in this circuit. The Hadamard gate prepares an equal superposition $\\frac{1}{\\sqrt{2}}(|0\\rangle+|1\\rangle)$ in qubit 0. This qubit controls an X gate on qubit 1. Since qubit 0 is in the equal superposition after the Hadamard gate, it will not apply the X gate for the first part of the superposition ($|0\\rangle$) and it will apply the X gate for the second part of the superposition ($|1\\rangle$). Thus we create the final state $\\frac{1}{\\sqrt{2}}(|00\\rangle+|11\\rangle)$, and we entangle the two qubit registers.\n",
    "\n",
    "A digital computer's processing unit typically has 64-bit registers and it is able to perform universal calculations on bit strings. Any complex calculation is broken down into elementary 64-bit operations, either sequentially or in parallel execution. So you may wonder what is the deal with the thousands of qubits we expect from a quantum computer. Why can't a 64-qubit quantum computer be enough?\n",
    "\n",
    "Entanglement is the easiest way to understand why we need so many qubits. Entanglement is a key resource in quantum computing and we want to make use of it. If we have 64-qubits and we want to entangle another one outside these 64 registers, we would have get rid of the qubit in one of the registers, potentially destroying a superposition ad definitely destroying entanglement between that register and any other qubit on the chip. The only way to make use of superpositions and the strong correlations provided by entanglement is if the entire problem is on the quantum processing unit for the duration of the calculation.\n",
    "\n",
    "This global nature of the calculation is also the reason why there is a focus on problems that are difficult to break down into elementary calculations. The travelling salesman problem is a great example: we need to consider all cities and all distances to minimize overall travel length.\n",
    "\n",
    "To finish off the circuit, we could add a measurement to each qubit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-19T20:07:25.136336Z",
     "start_time": "2018-11-19T20:07:24.318756Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/pwittek/.anaconda3/envs/qiskit/lib/python3.7/site-packages/qiskit/tools/visualization/_circuit_visualization.py:206: DeprecationWarning: The current behavior for the default output will change in a future release. Instead of trying latex and falling back to mpl on failure it will just use \"text\" by default\n",
      "  '\"text\" by default', DeprecationWarning)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAbQAAAC2CAIAAAA+6e+uAAA0+0lEQVR4nO3deVwTR98A8Em4wiWgIiioQTlEEBpaEK2WwxMvRASPKgriW7yrFY/aB6rwWC1Keaoo1cfgSTmUqsULFbBiUZFDDl8kXCI3yiGRM8f7x/Td0pBAjk02gfn+0c+6mZ38piS/7M7OzJK4XC5AFF9jY6OysjLRUfylp6dHV1dXVVWV6EAQgSZOnFhWVkZ0FOJQUVHp7u6WwRvJy9cJkcSvv/66evVqoqP4B1tb29zcXKKjQAQyMTHR1NT817/+RXQgoomPj793755s3gslx8FAV1cXAHD8+PGxY8cSHQsAAHz77bfjx48nOgqkPxQKZdSoUV5eXkQHIpqCgoIHDx7I5r1QchwMyGQyAGDevHlWVlZExwIAAMeOHdPQ0CA6CgSRCJnoABAEQeTRUEyOLBYLrw7drq4uXOpBEETeDMXkuGnTpnXr1uFSFZVKPXXqFC5VIchQlpaWJpt70MIbismxrq6urq4Ol6rs7OxOnDiBS1UIMmTdu3fPxcUlPT2d6ED+AZ/kyGazS0pKUlJSCgsLORwOLnUSS8gW+fr6FhUVPX36VJaxIchgwmazAwMDbW1tnZ2diY7lHyRNjhwOJyIiYty4cWZmZrNmzbK2tjYxMVHokymRWrRkyZIRI0bQ6XQZB4kggwadTs/Pzw8LC4ODLuSHRNF0dXV5eXnt3LmzpqYGAABHb1RWVm7fvt3b21sRTyFFbZGqquqXX34ZFxfX3t5OQLgIouCYTGZ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cdgMHR1dfX19YkORASenp5HjhzJz8+3s7NbvXr14J53z+Vyc3JyrKys1NTUiI4FAACam5tra2snT54s0lHm5uZ4JkesGwWbIjIgrJe0uLiYbwEs0VhZWWE7YWYkingxC6+iouLAgQPt7e3ihYfILRKJlJCQQHQUskAikeLj44mO4m8kEonL5Yp0iIODA57JEXtCgKDOuL6sra0pFEpnZ2dWVhbfAvn5+QAAPT09MzMzXIKUnLRjtrS0hN32CIIQCM8+R+xyrLCwUMhD1NTUFi9eDAB49OhRY2Mjz6tVVVXPnz8HACxdupTYs8XeFDFmBEFEhWdyHD9+/JgxYwAAN27cePXqVd8CeXl5kZGRPDt9fHwAAJ2dnTxrIwIAQkJC4Mmwr68vjnFKThFjRhBENPiunXv+/HlY7ejRo+Pj4xsbG9vb2xkMxpUrV5YuXUomk7du3dr3KLgOBYlEOnPmDLbz5MmT8Drd3d1d0Nvt27cPABARESF2wF5eXsbGxsbGxuXl5SIdKHbMCIIoBJyTI4fDmT9/vqBErKOjc+3atb5HVVVVYavG2tnZLV++HOuto1KptbW1gt5O8uTo7OwM36ikpESkA8WOGUEQhYDzeo4kEunGjRvBwcF6enq990+aNCksLKyysnLZsmV9jzIyMsrOznZ1dQUAZGdnX716lcFgAADmzZv37Nkz+ZwopogxIwgiPJHvcAupp6cHDnvU0dGhUqlCLuuQk5OTnJzc2NhobGzs6uo64HTI/fv3HzlyJCIiQpbTB3mIGjOCIApBWus5qqio2NnZiXoUjUaj0WjSiEd6FDFmBEEGRPwDthAEQeQQSo4IgiB8SPcZMlJy+/ZtOAsFrl7z4MGDzs5OAICjoyN8LCqCIIiEpHVDRqp8fX2xAZW97du374cffpB5OAiCDEL/B+oBTWp9pO0SAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGB size=436x182 at 0x7FBF46353F98>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "circuit.measure(q, c)\n",
    "circuit_drawer(circuit)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, we can plot the statistics:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-19T20:07:25.405506Z",
     "start_time": "2018-11-19T20:07:25.138810Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/pwittek/.anaconda3/envs/qiskit/lib/python3.7/site-packages/marshmallow/schema.py:364: ChangedInMarshmallow3Warning: strict=False is not recommended. In marshmallow 3.0, schemas will always be strict. See https://marshmallow.readthedocs.io/en/latest/upgrading.html#schemas-are-always-strict\n",
      "  ChangedInMarshmallow3Warning\n",
      "/home/pwittek/.anaconda3/envs/qiskit/lib/python3.7/site-packages/marshmallow/schema.py:364: ChangedInMarshmallow3Warning: strict=False is not recommended. In marshmallow 3.0, schemas will always be strict. See https://marshmallow.readthedocs.io/en/latest/upgrading.html#schemas-are-always-strict\n",
      "  ChangedInMarshmallow3Warning\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAdAAAAE+CAYAAAA9E0HyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3Xuc1nWd9/HXR06CC8jghIMEiCANh6VROmhodqdWdnfQ2tRstTXzTjfdcnfr7rC3unexu3bS7WS6beahMstyO7D6cHFXU8vEcQKZZiEEbmREBAICZHD83H9cFzSOM8NcP4aZYXg9H4/rMdfv9/v+vvO5nMfF29/p+43MRJIkVeaQvi5AkqQDkQEqSVIBBqgkSQUYoJIkFWCASpJUgAEqSVIBBqgkSQUYoJIkFWCASpJUgAEqSVIBg/u6gL40duzYnDhxYl+XIUnqRx5//PFnM7N6b+0O6gCdOHEiCxcu7Osy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fwgM58pt7kO+B8R8YmIeEVEfAJ4A3Btb30oSdLBp1dnY8nM2yNiLPBpoAZYApyRmbuPJie2a/+HiDiV0o1DvwY2AT8G/nebNg9FxDnAZ4Crgd8BZ2fmr/b355EkHbx69TnQ/sabiCRJ7fXHm4gkSRowDFBJkgowQCVJKsAAlSSpAANUkqQCDFBJkgowQCVJKsAAlaQDxL333surX/1qjj/+eK699qWDrX3nO99h2rRpnHzyyZx88sncfHNpYLfFixdz+umnc8IJJzBv3jzuvPPOPfusWrWKU089lblz53LhhRdWNBvJwc4AlaQDQGtrKx/72Mf4/ve/z8MPP8wPf/hDfvvb376k3Zlnnsn999/P/fffz/nnnw+UpvL6+te/zsMPP8wdd9zBpz71qT3TpF111VVccsklPProoxx++OHceuutvfq5DmQGqCQdABYtWsTRRx/N5MmTGTp0KGeddRYLFizo1r5Tp07lmGOOAUrziB5xxBE8++yzZCYPPPAA73jHOwA455xz+NnPfrbfPsNAY4BK0gGgubmZo446as/y+PHj90yM3dZPfvIT5s2bxwUXXLBnAu+2Fi1aREtLC0cffTQbN25k9OjRDB48uMs+1TEDVJIOAB2NWx4RL1p+85vfzOOPP84vfvELTjnlFP7yL//yRduffvppLrnkEr7yla9wyCGHdKtPdc4AlaQDwPjx43nqqaf2LK9du5YjjzzyRW2qqqoYNmwYAOeffz6PP/74nm1btmzhnHPO4ZOf/CSvetWrABg7diybN2/m+eef77RPdc4AlaQDwHHHHceKFStYtWoVLS0t3Hnnnbz5zW9+UZunn356z/sFCxZw7LHHAtDS0sL555/P2WefzTvf+c49bSKCefPmcddddwHwve99jzPOOKMXPs3A0KvzgUqSihk8eDDXXHMN7373u2ltbeW8886jtraW+fPnU1dXx1ve8hZuuOEGFixYwODBgxkzZgxf/epXAfjxj3/MQw89xMaNG/nud78LwFe/+lVmz57NVVddxUUXXcT8+fOZPXs273vf+/ryYx5QnA/U+UAlSW04H6gkSfuRASpJUgEGqCRJBRigkiQVYIBKklSAASpJUgEGqCRJBRigkiQVYIBKkl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ckZmfz8zZwKuA/6IUpt8Hvgzc0neVDkwegapD5VM9fwe8ndIg8g8D64FTgWbgosxc3HcVSgKIiDHAuMz8bXmksF1tbyaKiLOB7wLHZebjfVXnQGSAqkvlR1reCryT0rB9S4A7MvO3fVqYpE6VRwuLzGyNiA9SOn07oq/rGmgMUHWb05ZJB56IuAIYlJmf6+taBhoDVJIGsIgYArT6P789zwCVJKkA78KVJKkAA1SSpAIMUEmSCjBAJUkqwACVJKkAA1SSpAL+P0yCJD5EVxyXAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "backend = BasicAer.get_backend('qasm_simulator')\n",
    "job = execute(circuit, backend, shots=100)\n",
    "plot_histogram(job.result().get_counts(circuit))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As we have seen before, 01 and 10 never appear."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Compilation\n",
    "\n",
    "The circuit is the way to describe a quantum algorithm. It may also contain some arbitrary single or two-qubit unitary and controlled versions thereof. A quantum compiler should be able to decompose these into elementary gates."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For instance, in Qiskit, you can access to the general unitary using the $u3$ gate\n",
    "\n",
    "$$\n",
    "u3(\\theta, \\phi, \\lambda) = \\begin{pmatrix}\n",
    "\\cos(\\theta/2) & -e^{i\\lambda}\\sin(\\theta/2) \\\\\n",
    "e^{i\\phi}\\sin(\\theta/2) & e^{i\\lambda+i\\phi}\\cos(\\theta/2) \n",
    "\\end{pmatrix}.\n",
    "$$\n",
    "\n",
    "The compiler decomposes it into an actual gate sequence."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is one task of a quantum compiler. The next one is to translate the gates given in the circuit to the gates implemented in the hardware or the simulator. In the table above, we defined many gates, but a well-chosen set of three is sufficient for universality. For engineering constraints, typically one minimal set of universal gates is implemented in the hardware. It depends on the physical architecture which three.\n",
    "\n",
    "At this point, the number of gates applied is probably already increasing: the decomposition of unitary will create many gates and the translation of gates is also likely to add more gates. An additional problem is the topology of the qubits: in some implementations not all qubit registers are connected to each other. The most popular implementation is superconducting qubits, which are manufactured on silicon chips just like any digital device you have. Since this is a quintessentially two dimensional layout, most qubits on the chip will not be connected. Here is an example topology of eight qubits on a superconducting quantum computer:\n",
    "\n",
    "<img src=\"figures/eight_qubits.svg\" alt=\"8-qubit topology\" style=\"width: 200px;\"/>\n",
    "\n",
    "If we want to perform a two-qubit operations between two qubits that are not neighbouring, we have to perform SWAP operations to switch the qubit states between registers. A SWAP consists of three CNOT gates in a sequence.\n",
    "\n",
    "The total number of gates at the end of the compilation reflects the true requirement of the hardware. *Circuit depth* is the number of time steps required to execute the circuit, assuming that gates acting on distinct qubits can operate in parallel. On current and near-term quantum computers, we want circuits to be shallow, otherwise decoherence or other forms of noise destroy our calculations.\n",
    "\n",
    "We have to emphasize that the compilation depends on the backend. On the simulator, physical constraints do not apply. If we compile the circuit above, its depth will not increase:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-11-19T20:07:25.427084Z",
     "start_time": "2018-11-19T20:07:25.410103Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'name': 'u2',\n",
       "  'params': [0.0, 3.141592653589793],\n",
       "  'texparams': ['0', '\\\\pi'],\n",
       "  'qubits': [0],\n",
       "  'memory': []},\n",
       " {'name': 'cx', 'params': [], 'texparams': [], 'qubits': [0, 1], 'memory': []},\n",
       " {'name': 'measure',\n",
       "  'params': [],\n",
       "  'texparams': [],\n",
       "  'qubits': [0],\n",
       "  'memory': [0]},\n",
       " {'name': 'measure',\n",
       "  'params': [],\n",
       "  'texparams': [],\n",
       "  'qubits': [1],\n",
       "  'memory': [1]}]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from qiskit import compile\n",
    "compiled_circuit = compile(circuit, backend)\n",
    "compiled_circuit.as_dict()['experiments'][0]['instructions']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this case, the only thing the compiler did was replacing the Hadamard gate with a parametrized unitary operation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# References\n",
    "\n",
    "[1] M. Fingerhuth, T. Babej, P. Wittek. (2018). [Open source software in quantum computing](https://doi.org/10.1371/journal.pone.0208561). *PLOS ONE* 13(12):e0208561.  <a id='1'></a>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
